package com.dkm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dkm.entity.Message;
import com.dkm.entity.MessagePojo;
import com.dkm.entity.UserPojo;
import com.dkm.mapper.MessagePojoMapper;
import com.dkm.mapper.UserPojoMapper;
import com.dkm.service.UserPojoService;

@Service
public class UserPojoServiceImpl implements UserPojoService {
	//注入用户持久层
	@Autowired
	private UserPojoMapper userPojoMapper;
	
	//注入消息持久层
	@Autowired
	private MessagePojoMapper messagePojoMapper;
	
		
	@Override
	public List<UserPojo> getUserPojosExceptCurrentUser(String cur_user_id) {
		// TODO Auto-generated method stub
		return userPojoMapper.getUserPojosExceptCurrentUser(cur_user_id);
	}

	@Override
	public List<UserPojo> getUserMessages(String cur_user_id, List<UserPojo> users) {
		//遍历用户集合
		for (UserPojo user : users) {
			//根据发送人和接收人获取最新的10条消息
			List<MessagePojo> messages=messagePojoMapper.getMessagesBySender_idAndReceiver_id(cur_user_id, user.getUser_id());
			
			//如果消息不为空
			if(messages!=null&&messages.size()>0) {
				//设置给遍历的用户
				user.setMessages(messages);
			}
		}
		
		return users;
	}

}
